namespace nu.specs.Commands
{
    using System;
    using nu.Commands;
    using nu.Model;
    using NUnit.Framework;
    using NUnit.Framework.SyntaxHelpers;
    using Rhino.Mocks;
    using XF.Specs;

    [TestFixture]
    public class When_executing_the_inject_command : Spec
    {
        private InjectCommand cmd;
        private ILocalPackageRepository mockRepo;
        private IFileSystem mockFileSystem;

        protected override void Before_each_spec()
        {
            mockRepo = Mock<ILocalPackageRepository>();
            mockFileSystem = Mock<IFileSystem>();
            cmd = new InjectCommand(mockRepo, mockFileSystem);
        }

        [Test]
        public void What_is_the_commands_name()
        {
            Assert.That(cmd.Name, Is.EqualTo("Inject"));
        }

        [Test]
        public void Basic_execute_with_product_name()
        {
            using(Mocks.Record())
            {
                Expect.Call(mockRepo.Find("nunit")).Return(new Package("nunit"));
                mockFileSystem.Write(null);
            }
            using (Mocks.Playback())
            {
                cmd.Product = "nunit";

                cmd.Execute();
            }
        }

        [Test]
        public void Basic_execute_with_product_name_and_version()
        {
            using (Mocks.Record())
            {
                Expect.Call(mockRepo.Find("nunit")).Return(new Package("nunit"));
                mockFileSystem.Write(null);
            }
            using (Mocks.Playback())
            {
                cmd.Product = "nunit";
                cmd.Version = "2";

                cmd.Execute();
            }
        }

        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void Basic_execute_without_product_name()
        {
            using (Mocks.Record())
            {
                Expect.Call(mockRepo.Find("nunit")).Return(new Package("nunit"));
                mockFileSystem.Write(null);
            }
            using (Mocks.Playback())
            {
                cmd.Version = "2";

                cmd.Execute();
            }
        }
    }
}